﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication6.Models;
using MvcApplication6.DAL;

namespace MvcApplication6.BIZ
{
    public class MenuL3BIZ
    {
        MenuL3DAL DAL = new MenuL3DAL();

        ProductBIZ BIZ_product = new ProductBIZ();

        //---------------------Menu_l3Search-----------------------------
        public List<MenuL3Model> Menu_l3Select()
        {
            try
            {
                List<MenuL3Model> lst = new List<MenuL3Model>();
                lst = DAL.Menu_l3Select();

                return lst;
            }
            catch (Exception)
            {
                throw;
            }
        }
        //---------------------Menu_l3SearchById-----------------------------
        public MenuL3Model Menu_l3SearchById(int id)
        {
            try
            {
                MenuL3Model lst = DAL.Menu_l3SearchById(id);

                return lst;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l3SearchById_l2-----------------------------
        public List<MenuL3Model> Menu_l3SearchById_l2(int id_l2)
        {
            try
            {
                List<MenuL3Model> lst = new List<MenuL3Model>();
                lst = DAL.Menu_l3SearchById_l2(id_l2);

                return lst;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l3Insert-----------------------------
        public int Menu_l3Insert(int id_l2, string name, int position)
        {
            try
            {
                int i = DAL.Menu_l3Insert(id_l2, name, position);

                return i;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l3Update-----------------------------
        public int Menu_l3Update(int id, int id_l2, string name, int position)
        {
            try
            {
                int i = DAL.Menu_l3Update(id, id_l2, name, position);

                return i;
            }
            catch (Exception)
            {
                throw;
            }
        }

        //---------------------Menu_l3Delete-----------------------------
        public int Menu_l3Delete(int id)
        {
            try
            {
                int i = DAL.Menu_l3Delete(id);

                return i;
            }
            catch (Exception)
            {
                throw;
            }
        }
        //----------------------Delete menu L3 voi dk co san pham
        public int DeleteMenu_L3WhenHadProduct(int idmenu)
        {
            List<ProductModel> lst_model = new List<ProductModel>();

            lst_model = BIZ_product.ProductSearchById_l3(idmenu);
            int so_luong = lst_model.Count();

            if (so_luong == 0)
            {
                int i = Menu_l3Delete(idmenu);

                return i;
            }

            return -1;
        }
    }
}